function tag_edit() {
	var url = $(this).attr("href");
	var item = $(this).parent();
	var parentofitem = item.parent();
	parentofitem.load(url + "?ajax", 
		null,
		function () {
			$("form.edit_tags_form").submit(tag_save);
		}
	);
	return false;
}

$(document).ready(function () {
	$("ul.tag_list .edit").live("click", tag_edit);
});


function tag_save() {
	var item = $(this).parent(); // the tag_list <ul> element
	dish_id = item.find("#id_dish_id").val()
	var data = {
		dish_id: dish_id,
		tags: item.find("#id_tags").val()
	};
	$.post("/submit/tags/" + dish_id + "/?ajax", data, function (result) {
		if (result != "failure") {
			item.append(result);
			$(item[0].childNodes[0]).remove();
			//item.remove();
			//$("ul.tags .edit").click(tag_edit); // maybe not needed anymore because $().live()
		}
		else {
			alert("Failed to validate tags before saving.");
		}
	});
	return false;
}